<?xml version="1.0" encoding="Windows-1250"?>
<gxsl:stylesheet xmlns:gxsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/TransformAlias" version="1.0" xml:space="default">
  <gxsl:namespace-alias stylesheet-prefix="xsl" result-prefix="gxsl"/>
  <gxsl:output method="xml" version="1.0" encoding="windows-1250" indent="yes" cdata-section-elements="script"/>

  <gxsl:param name="lang">cs</gxsl:param>
  <gxsl:param name="baseurl"></gxsl:param>
  <gxsl:variable name="dict" select="document('dictionary.xml')/Translation"/>

  <gxsl:template match="/">      
    <xsl:stylesheet version="1.0" xmlns:d="http://www.metada.com/xda/diff">
      <xsl:output method="html" encoding="windows-1250" cdata-section-elements="script"/>

    <xsl:template match="DPOutput">
      <h4><gxsl:value-of select="$dict/Text[@tid='comparator_title']/Value[@lang=$lang]"/></h4>
      <xsl:apply-templates select="GenetOutput"/>
    </xsl:template>
  
    <xsl:template match="GenetOutput">

      <script language="JavaScript" type="text/javascript">
          <![CDATA[
            function compute()
            {
              var forms = document.forms; 
              var q = "<MultiQuery onerror='stop' xmlns:d='http://www.metada.com/xda/diff'>";
              for (i = 0; i < forms.length; i++)
              {
                var form = forms[i];
                if (form.name=='selection')
                {
                  var sInsert = "no";
                  var sUpdate = "no";
                  var e = form.elements;
                  for (j = 0; j < e.length; j++)
                  {
                    if (e[j].name=='delete' && e[j].checked)
                    {
                      q = q + "<DeleteData conceptview='" + form.cv.value + "'>" + form.xml.value + "</DeleteData>";
                    }
                    else if (e[j].name=='insert' && e[j].checked)
                    {
                      sInsert = "yes";
                    }
                    else if (e[j].name=='update' && e[j].checked)
                    {
                      sUpdate = "yes";
                    }
                  }
                  if (sInsert=="yes" || sUpdate=="yes")
                  {
                    q = q + "<UpdateData conceptview='" + form.cv.value + "' insert='"+sInsert+"' update='"+sUpdate+"'>" + form.xml.value + "</UpdateData>";
                  }
                }
              }
              q = q + "</MultiQuery>";
              forms.sub.query.value=q;
              forms.sub.action="]]><gxsl:value-of select="$baseurl"/><![CDATA[/xda";
              forms.sub.submit();
            }

            function getCookie(name)
            {
               var i=0;
               var suche = name+"=";
               while (i<document.cookie.length){
                  if (document.cookie.substring(i, i+suche.length)==suche){
                     var ende = document.cookie.indexOf(";", i+suche.length)
                     ende = (ende>-1) ? ende : document.cookie.length
                     var cook = document.cookie.substring(i+suche.length, ende)
                     return unescape(cook);
                  }
                  i++;
               }
               return null;
            }               

            function selectall(elem)
            {
              var forms = document.forms; 
              for (i = 0; i < forms.length; i++)
              {
                var form = forms[i];
                if (form.name=='selection')
                {
                  var e = form.elements;
                  for (j = 0; j < e.length; j++)
                    if (e[j].name=='delete' || e[j].name=='insert' || e[j].name=='update')                    
                      e[j].checked = elem.checked;
                }
              }
            }  

            function selectcov(elem, cov)
            {
              var forms = document.forms; 
              for (i = 0; i < forms.length; i++)
              {
                var form = forms[i];
                if (form.name=='selection' && form.cov.value==cov)
                {
                  var e = form.elements;
                  for (j = 0; j < e.length; j++)
                    if (e[j].name=='delete' || e[j].name=='insert' || e[j].name=='update')                    
                      e[j].checked = elem.checked;
                }
              }
            }  

            
            function showHide(elem, ctrl) {
              // innerText property implemented in Internet Explorer
              // textContent property implemented in Firefox
              if (ctrl.innerText=='[-]' || ctrl.textContent=='[-]') {
                elem.style.display='none';
                ctrl.innerText='[+]';
                ctrl.textContent='[+]';                
              } else {
                elem.style.display='block';
                ctrl.innerText='[-]';
                ctrl.textContent='[-]';                            
              }
            }                           
                     
            ]]>
        </script>
  
        <b>
          <xsl:if test="@type"> (<xsl:value-of select="@type"/>) </xsl:if>
          <xsl:value-of select="XDADiffResult[1]/@a"/> -> <xsl:value-of select="XDADiffResult[1]/@b"/> (<xsl:value-of select="XDADiffResult[1]/@time"/>)
        </b>
        <form name="sub" target="_blank" action="?" method="post">
          <input type="button" value="{$dict/Text[@tid='comparator_newsource']/Value[@lang=$lang]}" onclick="document.forms.newsource.submit();"/>
          <input type="button" value="{$dict/Text[@tid='comparator_regendiffstyle']/Value[@lang=$lang]}" onclick="document.forms.regendiffstyle.submit();"/>
          <input type="button" value="{$dict/Text[@tid='comparator_recompare']/Value[@lang=$lang]}" onclick="document.forms.recompare.submit();"/>
          <input type="button" value="{$dict/Text[@tid='comparator_synchronize']/Value[@lang=$lang]}" onclick="compute();"/>
  
          <p class="diff">
            <gxsl:value-of select="$dict/Text[@tid='comparator_sync_help']/Value[@lang=$lang]"/>
            <br/>
            <span class="sync_delete"><input name="xxxxdelete" type="checkbox" disabled="yes"/></span><b><gxsl:text>&#160;&#160;</gxsl:text><gxsl:value-of select="$dict/Text[@tid='comparator_sync_delete']/Value[@lang=$lang]"/> </b> - <gxsl:value-of select="$dict/Text[@tid='comparator_sync_delete_help']/Value[@lang=$lang]"/><br/>
            <span class="sync_insert"><input name="xxxxinsert" type="checkbox" disabled="yes"/></span><b><gxsl:text>&#160;&#160;</gxsl:text><gxsl:value-of select="$dict/Text[@tid='comparator_sync_insert']/Value[@lang=$lang]"/> </b> - <gxsl:value-of select="$dict/Text[@tid='comparator_sync_insert_help']/Value[@lang=$lang]"/><br/>
            <span class="sync_update"><input name="xxxxupdate" type="checkbox" disabled="yes"/></span><b><gxsl:text>&#160;&#160;</gxsl:text><gxsl:value-of select="$dict/Text[@tid='comparator_sync_update']/Value[@lang=$lang]"/> </b> - <gxsl:value-of select="$dict/Text[@tid='comparator_sync_update_help']/Value[@lang=$lang]"/><br/>
          </p>
  
          <input type="hidden" name="query"/>
          <input type="hidden" name="xdaname" value="{{XDADiffResult[1]/@system}}/{{XDADiffResult[1]/@b}}"/>
        </form>
        
        <form name="recompare" action="?" method="post">
          <input type="hidden" name="dp" value="compare"/>          
          <input type="hidden" name="sourcemodel" value="{{/DPOutput/DPParam[@name='sourcemodel']}}"/>
          <input type="hidden" name="targetmodel" value="{{/DPOutput/DPParam[@name='targetmodel']}}"/>
          <input type="hidden" name="targetmetamodel" value="{{/DPOutput/DPParam[@name='targetmetamodel']}}"/>
          <input type="hidden" name="regendiff" value="yes"/>
        </form>

        <form name="newsource" action="?" method="get">
          <input type="hidden" name="dp" value="main"/>          
        </form>

        <form name="regendiffstyle" action="?" method="post">
          <input type="hidden" name="dp" value="compare"/>          
          <input type="hidden" name="sourcemodel" value="{{/DPOutput/DPParam[@name='sourcemodel']}}"/>
          <input type="hidden" name="targetmodel" value="{{/DPOutput/DPParam[@name='targetmodel']}}"/>
          <input type="hidden" name="targetmetamodel" value="{{/DPOutput/DPParam[@name='targetmetamodel']}}"/>
          <input type="hidden" name="regendiffstyle" value="yes"/>
          <input type="hidden" name="nocache" value="yes"/>
        </form>

        <input type="checkbox" id="selectall" name="selectall" onclick="selectall(this)"/>&#160;<b><gxsl:value-of select="$dict/Text[@tid='select_all']/Value[@lang=$lang]"/></b>
  
        <xsl:apply-templates select="XDADiffResult"/>
      </xsl:template>
    
      <xsl:template match="XDADiffResult">
        <xsl:apply-templates/>
      </xsl:template>
  
      <xsl:template name="show_attr_diff">
        <xsl:param name="prop_title"/>
        <xsl:choose>
          <xsl:when test="@st='add'">
            <font class="diff_proptitle"><xsl:value-of select="$prop_title"/>:</font>
            <font class="diff"> -> </font>
            <font class="diff_new"><xsl:value-of select="@val"/></font><br/>
          </xsl:when>
          <xsl:when test="@st='mod'">
            <font class="diff_proptitle"><xsl:value-of select="$prop_title"/>: </font>
            <font class="diff_old"><xsl:value-of select="@a"/></font>
            <font class="diff"> -> </font>
            <font class="diff_new"><xsl:value-of select="@b"/></font><br/>
          </xsl:when>
          <xsl:when test="@st='remove'">
            <font class="diff_proptitle"><xsl:value-of select="$prop_title"/>: </font>
            <font class="diff_old"><xsl:value-of select="@val"/></font>
            <font class="diff"> -> </font><br/>
          </xsl:when>
        </xsl:choose>
      </xsl:template> 
  
      <xsl:template name="show_text_diff" xmlns:d="http://www.metada.com/xda/diff">
        <xsl:param name="prop_title"/>
        <xsl:choose>
          <xsl:when test="@st='add'">
            <font class="diff_proptitle"><xsl:value-of select="$prop_title"/>:</font>
            <font class="diff"> -> </font>
            <font class="diff_new"><xsl:value-of select="."/></font><br/>
          </xsl:when>
          <xsl:when test="@st='remove'">
            <font class="diff_proptitle"><xsl:value-of select="$prop_title"/>: </font>
            <font class="diff_old"><xsl:value-of select="."/></font>
            <font class="diff"> -> </font><br/>
          </xsl:when>
          <xsl:when test="@st='mod'">
            <font class="diff_proptitle"><xsl:value-of select="$prop_title"/>: </font>
            <font class="diff_old"><xsl:value-of select="d:a"/></font>
            <font class="diff"> -> </font>
            <font class="diff_new"><xsl:value-of select="d:b"/></font><br/>
          </xsl:when>
        </xsl:choose>
      </xsl:template> 
  
      <gxsl:apply-templates select="CViews/CView"/>
        
      <xsl:template name="title"><gxsl:value-of select="$dict/Text[@tid='comparator_title']/Value[@lang=$lang]"/></xsl:template>
                    
    </xsl:stylesheet>
  </gxsl:template>

  
  <gxsl:template match="CView">

    <xsl:template match="coverer_{CVInclude/@concept}[{CVInclude/@nickcoll}/{CVInclude/@nickname}]">
      <gxsl:variable name="tit"><gxsl:value-of select="CVInclude/CVITitles/CVITitle[@id_cttype='listtitle' and @id_lang=$lang]/Title"/></gxsl:variable>
      <h3>
        <gxsl:choose>
          <gxsl:when test="$tit and $tit!=''">
            <gxsl:value-of select="$tit"/>
          </gxsl:when>
          <gxsl:otherwise>
            <gxsl:value-of select="CVInclude/@concept"/>
          </gxsl:otherwise>
        </gxsl:choose>
        <text/>&#160;<span style="cursor:pointer" onclick="showHide(document.getElementById('cov{CVInclude/@concept}'), this)">[-]</span>
      </h3>
      <p id="cov{CVInclude/@concept}">      
        <table><tr><td width="10"></td>
          <td valign="top">
            <input type="checkbox" id="selectcov" name="selectcov" onclick="selectcov(this, '{CVInclude/@concept}')"/>&#160;<font class="diff"><gxsl:value-of select="$dict/Text[@tid='select_cov']/Value[@lang=$lang]"/></font>
          </td>
        </tr></table>
        <gxsl:apply-templates select="CVInclude"/>
      </p>
    </xsl:template>
 
  </gxsl:template>


  <gxsl:template match="CVInclude">
  
    <xsl:if test="{@nickcoll}[@d:st]">
      <xsl:for-each select="{@nickcoll}/{@nickname}">

        <gxsl:variable name="title_real">
          <gxsl:value-of select="CVITitles/CVITitle[@id_cttype='maintitle' and @id_lang=$lang]/Title"/>
        </gxsl:variable>
        <xsl:variable name="title">
          <gxsl:choose>
            <gxsl:when test="$title_real!=''"><gxsl:value-of select="$title_real"/></gxsl:when>
            <gxsl:otherwise><gxsl:value-of select="@nickcoll"/></gxsl:otherwise>
          </gxsl:choose>
          <gxsl:text>: </gxsl:text>
          <gxsl:choose>
            <gxsl:when test="count(CVIProperties/CVIProperty[@onlabel='1'])>0">
              <gxsl:for-each select="CVIProperties/CVIProperty[@onlabel='1']">
                <gxsl:choose>
                  <gxsl:when test="@attr='1'">
                    <xsl:value-of select="@{@nicknamelow}"/><xsl:text>&#160;</xsl:text>
                  </gxsl:when>
                  <gxsl:otherwise>
                    <xsl:value-of select="{@nickname}/text()"/><xsl:text>&#160;</xsl:text>
                  </gxsl:otherwise>
                </gxsl:choose>
              </gxsl:for-each>
            </gxsl:when>
            <gxsl:otherwise>
              <gxsl:for-each select="CVIProperties/CVIProperty[@key='1']">
                <xsl:value-of select="@{@nicknamelow}"/><xsl:text>&#160;</xsl:text>
              </gxsl:for-each>
            </gxsl:otherwise>
          </gxsl:choose>
        </xsl:variable>
  
        <table><tr><td width="10"></td>
  
          <td valign="top">
          
          <xsl:choose>
            <xsl:when test="../@d:st='add'">
              <font class="diff_objtitle_new"><xsl:value-of select="$title"/></font><br/>
            </xsl:when>
            <xsl:when test="../@d:st='remove'">
              <font class="diff_objtitle_old"><xsl:value-of select="$title"/></font><br/>
            </xsl:when>
            <xsl:otherwise>
              <font class="diff_objtitle"><xsl:value-of select="$title"/></font><br/>
            </xsl:otherwise>
          </xsl:choose>
        </td></tr></table>
  

      </xsl:for-each>
    </xsl:if>
    <xsl:for-each select="{@nickcoll}/{@nickname}[descendant-or-self::*/@d:st or descendant-or-self::*/d:attr or descendant-or-self::*/d:text]">
      <gxsl:variable name="title_real">
        <gxsl:value-of select="CVITitles/CVITitle[@id_cttype='maintitle' and @id_lang=$lang]/Title"/>
      </gxsl:variable>
      <xsl:variable name="title">
        <gxsl:choose>
          <gxsl:when test="$title_real!=''"><gxsl:value-of select="$title_real"/></gxsl:when>
          <gxsl:otherwise><gxsl:value-of select="@nickcoll"/></gxsl:otherwise>
        </gxsl:choose>
        <gxsl:text>: </gxsl:text>
        <gxsl:choose>
          <gxsl:when test="count(CVIProperties/CVIProperty[@onlabel='1'])>0">
            <gxsl:for-each select="CVIProperties/CVIProperty[@onlabel='1']">
              <gxsl:choose>
                <gxsl:when test="@attr='1'">
                  <xsl:choose>
                    <xsl:when test="d:attr[@name='{@nickname}' and (@st='mod' or @st='add')]">
                      <xsl:value-of select="d:attr[@name='{@nickname}' and (@st='mod' or @st='add')]/@b"/><xsl:text>&#160;</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="@{@nicknamelow}"/><xsl:text>&#160;</xsl:text>
                    </xsl:otherwise>
                  </xsl:choose>
                </gxsl:when>
                <gxsl:otherwise>
                  <xsl:choose>
                    <xsl:when test="d:text[@name='{@nickname}' and (@st='mod' or @st='add')]">
                      <xsl:value-of select="d:text[@name='{@nickname}' and (@st='mod' or @st='add')]/d:b"/><xsl:text>&#160;</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="{@nickname}/text()"/><xsl:text>&#160;</xsl:text>
                    </xsl:otherwise>
                  </xsl:choose>
                </gxsl:otherwise>
              </gxsl:choose>
            </gxsl:for-each>
          </gxsl:when>
          <gxsl:otherwise>
            <gxsl:for-each select="CVIProperties/CVIProperty[@key='1']">
              <xsl:value-of select="@{@nicknamelow}"/><xsl:text>&#160;</xsl:text>
            </gxsl:for-each>
          </gxsl:otherwise>
        </gxsl:choose>
      </xsl:variable>

      <table border="0"><tr><td width="10"></td>

        <gxsl:if test="name(..)='CView'">
          <form name="selection">
            <input type="hidden" name="cov" value="{@concept}"/>
            <td valign="top">
              <xsl:choose>
                <xsl:when test="@d:st='add' or .//node()/@d:st='add'">
                  <span class="sync_delete"><input type="checkbox" name="delete"/></span>
                </xsl:when>
              </xsl:choose>
              <xsl:choose>
                <xsl:when test="@d:st='remove' or .//node()/@d:st='remove'">
                  <span class="sync_insert"><input type="checkbox" name="insert"/></span>
                </xsl:when>
              </xsl:choose>
              <xsl:choose>
                <xsl:when test=".//d:attr or .//d:text">
                  <span class="sync_update"><input type="checkbox" name="update"/></span>
                </xsl:when>
              </xsl:choose>
              <textarea name="xml" cols="1" rows="1" style="visibility: hidden; width: 1; height: 1;"><xsl:text disable-output-escaping="yes">&lt;</xsl:text><gxsl:value-of select="../@name"/><xsl:text disable-output-escaping="yes">&gt;&lt;</xsl:text><gxsl:value-of select="@nickcoll"/><xsl:text disable-output-escaping="yes">&gt;</xsl:text><xsl:copy-of select="."/><xsl:text disable-output-escaping="yes">&lt;</xsl:text>/<gxsl:value-of select="@nickcoll"/><xsl:text disable-output-escaping="yes">&gt;&lt;</xsl:text>/<gxsl:value-of select="../@name"/><xsl:text disable-output-escaping="yes">&gt;</xsl:text></textarea>
              <input type="hidden" name="cv" value="coverer_{@concept}"/>
            </td>
          </form>
        </gxsl:if>
        <td valign="top">
        
        <xsl:choose>
          <xsl:when test="@d:st='add'">
            <font class="diff_objtitle_new"><xsl:value-of select="$title"/></font><br/>
          </xsl:when>
          <xsl:when test="@d:st='remove'">
            <font class="diff_objtitle_old"><xsl:value-of select="$title"/></font><br/>
          </xsl:when>
          <xsl:otherwise>
            <font class="diff_objtitle"><xsl:value-of select="$title"/></font><br/>
          </xsl:otherwise>
        </xsl:choose>

        
        <xsl:if test="count(d:attr)>0 or count(d:text)>0">
          <table><tr><td width="10"></td><td>
            <gxsl:for-each select="CVIProperties/CVIProperty">
              <gxsl:choose>
                <gxsl:when test="@attr='1'">
                  <xsl:for-each select="d:attr[@name='{@nicknamelow}']">
                    <xsl:call-template name="show_attr_diff">
                      <xsl:with-param name="prop_title"><gxsl:value-of select="Title"/></xsl:with-param>
                    </xsl:call-template>
                  </xsl:for-each>
                </gxsl:when>
                <gxsl:otherwise>
                  <xsl:for-each select="d:text[@name='{@nickname}']">
                    <xsl:call-template name="show_text_diff">
                      <xsl:with-param name="prop_title"><gxsl:value-of select="Title"/></xsl:with-param>
                    </xsl:call-template>
                  </xsl:for-each>
                </gxsl:otherwise>
              </gxsl:choose>
            </gxsl:for-each>
          </td></tr></table>
        </xsl:if>
        
        <gxsl:apply-templates select="CVIRels/CVIRel/CVInclude"/>
      </td></tr></table>
    </xsl:for-each>
  </gxsl:template>

</gxsl:stylesheet>
